<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('配置集货库位和暂存库位管理') "/>

<body style="background-color: #f2f2f2;">
<div id="title" class="layui-input">
    <input type="text" class="layui-input" readonly value="配置集货库位和暂存库位"/><input style="position: absolute;right: 0;" th:value="${mc}"  class="layui-input" readonly/>
</div>
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <input type="hidden" class="layui-input" th:value="${id}" id="sshzid" name="sshzid"/>
                    <div class="layui-inline">
                        <label class="layui-form-label">集货库位</label>
                        <div class="layui-input-inline">
                            <select lay-ignore="lay-ignore" class="js-data-example-ajax"  id="jhqkwid" name="jhqkwMc" data-required style="width: 196px;height: 40px"></select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">暂存库位</label>
                        <div class="layui-input-inline">
                            <select lay-ignore="lay-ignore" class="js-data-example-ajaxs"  id="djcwid" name="djcwMc" data-required style="width: 196px;height: 40px"></select>
                        </div>
                    </div>
                </form>
                <!--顶部按钮展示区域 【 tpl-button 】 -->
                <div class="group-button tpl-button" id="toolbar"></div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table" class="table text-nowrap"></table>
                    </div>
                </section>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" jq-filter="submit" lay-submit="" lay-filter="addOwerjz">立即提交</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

</body>
<div th:include="public/public_js::public_js"></div>
<div th:include="public/public_btn::public_btn"></div>
<style type="text/css">
    .moreBtn {
        width: 50px;
        height: 20px;
        text-align: center;
        color: #fff;
        line-height: 20px;
        background-color: #eee;
        position: relative;
        margin: 0 auto;
        cursor: pointer;
    }

    .moreBtn:before {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(30deg);
        background: #eee;
        border-top-left-radius: 8px;
        left: -20px;
        top: 0;
    }

    .moreBtn:after {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(-30deg);
        background: #eee;
        border-top-right-radius: 8px;
        top: 0;
        right: -20px;
    }
    #title{
        height: 4rem;
        border-radius: 5px;
    }
    #title input{
        display: inline-block;
        width: 20rem;
        border: 0;
        background-color: white;
    }
</style>
<script th:inline="javascript">
    var ids=$("#sshzid").val();
    var functions = [[${functions}]];
    var oneReq = [];
    var oneReqs = [];

    //查已绑定货主的集货或者暂存库位集合select2的
    $(function () {
        $.ajax({
            url:"/zxsdwms/wmsOwner/getAllKwSelectTwo",
            type: 'POST',
            dataType: 'json',
            contentType: "application/json",
            async: false,
            data: JSON.stringify({"jhqkwMc": $('#jhqkwid').val(),"sshzid":$("#sshzid").val(),"kwlx":'5'}),
            success: function(data){
                oneReq = data;
            }
        })
        var datas = [{id:'', text: ''}];
        oneReq.forEach(function (item) {
            datas.push({id: item.id, text: item.mc});
        });
        $('.js-data-example-ajax').select2({
            data: datas,
            language: "zh-CN",
            placeholder: '请输入查询字段',
            allowClear: true
        });

        //暂存
        $.ajax({
            url:"/zxsdwms/wmsOwner/getAllKwSelectTwo",
            type: 'POST',
            dataType: 'json',
            contentType: "application/json",
            async: false,
            data: JSON.stringify({"jhqkwMc": $('#djcwid').val(),"sshzid":$("#sshzid").val(),"kwlx":'4'}),
            success: function(data){
                oneReqs = data;
            }

        })
        var datad = [{id:'', text: ''}];
        oneReqs.forEach(function (item) {
            datad.push({id: item.id, text: item.mc});
        });
        $('.js-data-example-ajaxs').select2({
            data: datad,
            language: "zh-CN",
            placeholder: '请输入查询字段',
            allowClear: true
        });

    })

    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate','tablebutton'], function () {
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate,
            tablebtn = layui.tablebutton;
        var form = layui.form;
        var $table;
        var da=[];

        $.ajax({
            url:"/zxsdwms/wmsOwner/getAllKw",
            type: 'POST',
            dataType: 'json',
            contentType: "application/json",
            data: JSON.stringify({id:ids}),
            async: false,
            success: function(data){
                zzpUtils.loadJsonDataToForm(data);
                $('#jhqkwid').val([data.jhqkwid]).trigger('change');
                $('#djcwid').val([data.djcwid]).trigger('change');
            }
        })
        $(".inline-search-btn").on('click',function () {
            zzpUtils.refreshTable("#table");
        })
        //保存货主订单类型的ids
        form.on("submit(addOwerjz)",function(data){

            if($('#jhqkwid').val()!=null && $('#jhqkwid').val()!=''){
                if($('#djcwid').val()!=null && $('#djcwid').val()!=''){
                    var data = {
                        "jhqkwMc":$('#jhqkwid').val(),
                        "djcwMc":$('#djcwid').val(),
                        "id":$('#sshzid').val()
                    };
                }else{
                    layer.msg("暂存库位必填",{icon: 5});
                }
            }else{
                layer.msg("集货库位必填",{icon: 5});
            }
            zzpUtils.confirm("是否确定保存",function(index){
                zzpUtils.action({
                    url:"/wmsOwner/addAllKw",
                    data:JSON.stringify(data),
                    success:function (data) {
                        setTimeout(function(){
                            if(data.type=="success"){
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index); //再执行关闭
                                top.layer.msg(data.title);
                            }else{
                                layer.confirm(data.message,{btn: ['确定'],title:data.title,icon: 2});
                            }

                        },500);
                    },error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr);
                    }
                })
            })

            return false;
        });
    });

</script>
</html>